
//
//  MyJourneyDetailDriverView.m
//  didihaha
//
//  Created by 赵忠鹏 on 2017/8/18.
//  Copyright © 2017年 zhaozhongpeng. All rights reserved.
//

#import "MyJourneyDetailDriverView.h"
#import "Masonry.h"
#import "MyJourneyButton.h"

@interface MyJourneyDetailDriverView ()

/**
 老司机头像
 */
@property (nonatomic, strong)UIImageView *driverLogoImageView;

@property (nonatomic, strong)UILabel *driveName;

@property (nonatomic, strong)UILabel *carNo;

@property (nonatomic, strong)UILabel *carCompany;

#pragma 联系按钮

@property (nonatomic, strong)UIButton *sendMessageBtn;

@property (nonatomic, strong)UIButton *sendCallPerson;

#pragma 线
@property (nonatomic, strong)UIView *topline;
@property (nonatomic, strong)UIView *middleLine;
@property (nonatomic, strong)UIView *bottomLine;
@property (nonatomic, strong)UIView *otherBottomLine;

#pragma 联系客服 、 紧急求助
@property (nonatomic, strong)UIButton *contactServiceBtn;
@property (nonatomic, strong)UIButton *emergencyCallingBtn;

#pragma 评价本次服务
@property (nonatomic, strong)MyJourneyButton *evaluateBtn;

#pragma mark - 金额
@property (nonatomic, strong)UILabel *moneyLabel;

#pragma mark - 明细
@property (nonatomic, strong)MyJourneyButton *detailBtn;
@property (nonatomic, strong)MyJourneyButton *conversionBtn;

@end

@implementation MyJourneyDetailDriverView

- (instancetype)init{
    self = [super init];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        self.layer.cornerRadius = 3;
        self.layer.shadowColor = [UIColor lightGrayColor].CGColor;
        self.layer.shadowOffset = CGSizeMake(0,-2);
        self.layer.shadowOpacity = 0.5;
        self.layer.borderWidth = 0.1;
        self.layer.borderColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:240/255.0 alpha:1].CGColor;
        [self createUI];
    }
    return self;
}


- (void)createUI{
    
    [self addSubview:self.driverLogoImageView];// 老司机头像
    [self addSubview:self.driveName];// 老司机 name
    [self addSubview:self.carNo];// 老司机 序号
    [self addSubview:self.carCompany];// 老司机 攻丝
    [self addSubview:self.sendMessageBtn];// 发信息
    [self addSubview:self.sendCallPerson]; // 打电话
    [self addSubview:self.topline];
    [self addSubview:self.middleLine];
    [self addSubview:self.bottomLine];
    [self addSubview:self.otherBottomLine];
    [self addSubview:self.contactServiceBtn];// 联系客服
    [self addSubview:self.emergencyCallingBtn];// 紧急联系人
    [self addSubview:self.evaluateBtn];// 评价本次服务
    [self addSubview:self.moneyLabel]; // 钱
    [self addSubview:self.detailBtn]; // 明细
    [self addSubview:self.conversionBtn]; // 兑换
    
    // 老司机头像
    [self.driverLogoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(10);
        make.top.equalTo(self.mas_top).offset(15);
        make.height.width.mas_equalTo(60);
    }];
    
    // 老司机 name
    [self.driveName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.driverLogoImageView.mas_right).offset(8);
        make.top.equalTo(self.driverLogoImageView.mas_top);
    }];
    // 老司机 序号
    [self.carNo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.driveName);
        make.centerY.equalTo(self.driverLogoImageView.mas_centerY);
    }];
    
    // 老司机 攻丝
    [self.carCompany mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.driverLogoImageView.mas_bottom);
        make.left.equalTo(self.driveName);
    }];
    // 打电话
    [self.sendCallPerson mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).offset(-15);
        make.centerY.equalTo(self.driverLogoImageView.mas_centerY);
        make.width.height.mas_equalTo(30);
    }];
    
    // 发信息
    [self.sendMessageBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.width.height.equalTo(self.sendCallPerson);
        make.right.equalTo(self.sendCallPerson.mas_left).offset(-15);
    }];
    
    // 线
    [self.topline mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self);
        make.top.equalTo(self.driverLogoImageView.mas_bottom).offset(15);
        make.height.mas_equalTo(1);
    }];
    
    
    [self.bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.height.equalTo(self.topline);
        make.top.equalTo(self.topline.mas_bottom).offset(44);
    }];
    
    [self.middleLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.topline.mas_bottom);
        make.bottom.equalTo(self.bottomLine.mas_top);
        make.width.mas_equalTo(1);
        make.centerX.equalTo(self);
    }];
    
    [self.otherBottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self);
        make.bottom.equalTo(self.mas_bottom).offset(-44);
        make.height.equalTo(self.topline);
    }];
    // 联系客服
    [self.contactServiceBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self);
        make.top.equalTo(self.topline.mas_bottom);
        make.bottom.equalTo(self.bottomLine.mas_top);
        make.right.equalTo(self.middleLine.mas_left);
    }];
    
    
    // 紧急救援
    [self.emergencyCallingBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.middleLine.mas_right);
        make.top.equalTo(self.topline.mas_bottom);
        make.bottom.equalTo(self.bottomLine.mas_bottom);
        make.right.equalTo(self.mas_right);
    }];
    
    [self.evaluateBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self);
        make.top.equalTo(self.otherBottomLine.mas_bottom);
    }];
    
    
    [self.moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.top.equalTo(self.bottomLine.mas_bottom).offset(43);
    }];
    
    [self.detailBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.moneyLabel.mas_bottom).offset(6);
        make.right.equalTo(self.mas_centerX).offset(-10);
    }];
    
    [self.conversionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.detailBtn);
        make.left.equalTo(self.mas_centerX).offset(10);
    }];
    
}

#pragma mark - 懒加载
// 老司机头像
- (UIImageView *)driverLogoImageView{
    if (_driverLogoImageView == nil) {
        _driverLogoImageView = [[UIImageView alloc] init];
        _driverLogoImageView.image = [UIImage imageNamed:@"driver_head"];
        _driverLogoImageView.clipsToBounds = YES;
        _driverLogoImageView.layer.cornerRadius = 30;
    }
    return _driverLogoImageView;
}

- (UILabel *)driveName{
    if (_driveName == nil) {
        _driveName = [[UILabel alloc] init];
        _driveName.text = @"姜师傅";
        _driveName.font = [UIFont systemFontOfSize:15];
    }
    return _driveName;
}

- (UILabel *)carNo{
    if (_carNo == nil) {
        _carNo = [[UILabel alloc] init];
        _carNo.font = [UIFont systemFontOfSize:12];
        _carNo.text = @"京BP4807";
        _carNo.backgroundColor = [UIColor colorWithRed:234/255.0 green:234/255.0 blue:234/255.0 alpha:1];
        _carNo.layer.borderWidth = 0.2;
        _carNo.layer.borderColor = [UIColor colorWithRed:195/255.0 green:195/255.0 blue:195/255.0 alpha:1].CGColor;
    }
    return _carNo;
}

- (UILabel *)carCompany{
    if (_carCompany == nil) {
        _carCompany = [[UILabel alloc] init];
        _carCompany.font = [UIFont systemFontOfSize:13];
        _carCompany.text = @"京城联昌华德";
        _carCompany.textColor = [UIColor lightGrayColor];
    }
    return _carCompany;
}

- (UIButton *)sendMessageBtn{
    if (_sendMessageBtn == nil) {
        _sendMessageBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_sendMessageBtn setImage:[UIImage imageNamed:@"service_btn_IM_hover"] forState:UIControlStateHighlighted];
        [_sendMessageBtn setImage:[UIImage imageNamed:@"service_btn_IM"] forState:UIControlStateNormal];
        [_sendMessageBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _sendMessageBtn;
}

- (UIButton *)sendCallPerson{
    if (_sendCallPerson == nil) {
        _sendCallPerson = [UIButton buttonWithType:UIButtonTypeCustom];
        [_sendCallPerson setImage:[UIImage imageNamed:@"service_btn_call_hover"] forState:UIControlStateHighlighted];
        [_sendCallPerson setImage:[UIImage imageNamed:@"service_btn_call"] forState:UIControlStateNormal];
        [_sendCallPerson addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _sendCallPerson;
}

- (UIView *)topline{
    if (_topline == nil) {
        _topline = [[UIView alloc] init];
        _topline.backgroundColor = [UIColor colorWithRed:242/255.0 green:242/255.0 blue:242/255.0 alpha:1];
    }
    return _topline;
}

- (UIView *)middleLine{
    if (_middleLine == nil) {
        _middleLine = [[UIView alloc] init];
        _middleLine.backgroundColor = [UIColor colorWithRed:242/255.0 green:242/255.0 blue:242/255.0 alpha:1];
    }
    return _middleLine;
}

- (UIView *)bottomLine{
    if (_bottomLine == nil) {
        _bottomLine = [[UIView alloc] init];
        _bottomLine.backgroundColor = [UIColor colorWithRed:242/255.0 green:242/255.0 blue:242/255.0 alpha:1];
    }
    return _bottomLine;
}

- (UIView *)otherBottomLine{
    if (_otherBottomLine == nil) {
        _otherBottomLine = [[UIView alloc] init];
        _otherBottomLine.backgroundColor = [UIColor colorWithRed:242/255.0 green:242/255.0 blue:242/255.0 alpha:1];
    }
    return _otherBottomLine;
}

#pragma mark - 联系客服 、 紧急求助

- (UIButton *)contactServiceBtn{
    if (_contactServiceBtn == nil) {
        _contactServiceBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_contactServiceBtn setTitle:@"联系客服" forState:UIControlStateNormal];
        _contactServiceBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        [_contactServiceBtn setTitleColor:[UIColor colorWithRed:89/255.0 green:89/255.0 blue:89/255.0 alpha:1] forState:UIControlStateNormal];
    }
    return _contactServiceBtn;
}


- (UIButton *)emergencyCallingBtn{
    if (_emergencyCallingBtn == nil) {
        _emergencyCallingBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_emergencyCallingBtn setTitle:@"紧急求助" forState:UIControlStateNormal];
        _emergencyCallingBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        [_emergencyCallingBtn setTitleColor:[UIColor colorWithRed:89/255.0 green:89/255.0 blue:89/255.0 alpha:1] forState:UIControlStateNormal];
    }
    return _emergencyCallingBtn;
}

#pragma mark - 评价本次服务
- (MyJourneyButton *)evaluateBtn{
    if (_evaluateBtn == nil) {
        _evaluateBtn = [MyJourneyButton buttonWithType:UIButtonTypeCustom];
        [_evaluateBtn setImage:[UIImage imageNamed:@"od_gray_arrow"] forState:UIControlStateNormal];
        _evaluateBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        [_evaluateBtn setTitleColor:[UIColor colorWithRed:89/255.0 green:89/255.0 blue:89/255.0 alpha:1] forState:UIControlStateNormal];
        [_evaluateBtn setTitle:@"评价本次服务 " forState:UIControlStateNormal];
    }
    return _evaluateBtn;
}

#pragma 金额
- (UILabel *)moneyLabel{
    if (_moneyLabel == nil) {
        _moneyLabel = [[UILabel alloc] init];
        _moneyLabel.textColor = [UIColor colorWithRed:89/255.0 green:89/255.0 blue:89/255.0 alpha:1];
        _moneyLabel.font = [UIFont systemFontOfSize:12];
        _moneyLabel.text = @"共 118.00 元";
        
    }
    return _moneyLabel;
}

- (MyJourneyButton *)detailBtn{
    if (_detailBtn == nil) {
        _detailBtn = [MyJourneyButton buttonWithType:UIButtonTypeCustom];
        [_detailBtn setImage:[UIImage imageNamed:@"od_gray_arrow"] forState:UIControlStateNormal];
        _detailBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        [_detailBtn setTitleColor:[UIColor colorWithRed:89/255.0 green:89/255.0 blue:89/255.0 alpha:1] forState:UIControlStateNormal];
        [_detailBtn setTitle:@"查看明细 " forState:UIControlStateNormal];
    }
    return _detailBtn;
}

- (MyJourneyButton *)conversionBtn{
    if (_conversionBtn == nil) {
        _conversionBtn = [MyJourneyButton buttonWithType:UIButtonTypeCustom];
        [_conversionBtn setImage:[UIImage imageNamed:@"od_gray_arrow"] forState:UIControlStateNormal];
        _conversionBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        [_conversionBtn setTitleColor:[UIColor colorWithRed:89/255.0 green:89/255.0 blue:89/255.0 alpha:1] forState:UIControlStateNormal];
        [_conversionBtn setTitle:@"滴币兑换 " forState:UIControlStateNormal];
    }
    return _conversionBtn;
}


#pragma mark - 按钮触发方法

- (void)btnClick:(UIButton *)btn{

}

#pragma mark - setter
- (void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    
    self.driveName.text = [dataDic objectForKey:@"driveName"];
    self.carNo.text = [NSString stringWithFormat:@" %@ ",[dataDic objectForKey:@"carNo"]];
    self.carCompany.text = [dataDic objectForKey:@"driveCompany"];
    
    NSString *tempStr = [NSString stringWithFormat:@"共 %@ 元",[dataDic objectForKey:@"moneyCount"]];
    NSMutableAttributedString *tempAtt = [[NSMutableAttributedString alloc] initWithString:tempStr];
    [tempAtt setAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:30]} range:NSMakeRange(1, tempStr.length - 2)];
    self.moneyLabel.attributedText = tempAtt;
     
}


@end
